package com.suman.bbcticker.configure;



import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;

import com.suman.bbcticker.Eula;
import com.suman.bbcticker.R;

public class FeedTickerPreferences extends PreferenceActivity {
	private static final String SELECTED_TEXT="Value Selected is ";

	
	  @Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        Eula.showEula(this);
	        addPreferencesFromResource(R.xml.preferences);
	        Preference feedRefreshTimePreference = getPreferenceScreen().findPreference(PreferenceLauncherActivity.TICKER_ALERTTYPE_FEEDREFRESHTIME_KEY);
	        feedRefreshTimePreference.setOnPreferenceChangeListener(onPreferenceChangeListenerImpl());
	        
	        Preference alertTypeNotificationPreference = getPreferenceScreen().findPreference(PreferenceLauncherActivity.TICKER_ALERTTYPE_NOTIFICATION_KEY);
	        alertTypeNotificationPreference.setOnPreferenceChangeListener(onPreferenceChangeListenerImpl());
	        
	        Preference siteSelectionPreference = getPreferenceScreen().findPreference(PreferenceLauncherActivity.TICKER_ALERTTYPE_SITESELECTED_KEY);
	        siteSelectionPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener(){
				public boolean onPreferenceChange(Preference preference, Object newValue) {
					ListPreference siteSelectionPreference = (ListPreference)preference;
					preference.setSummary(SELECTED_TEXT + siteSelectionPreference.getEntry());
					return true;
				}
				
			});
	        
	        Preference alertTypeSoundPreference = getPreferenceScreen().findPreference(PreferenceLauncherActivity.TICKER_ALERTTYPE_SOUND_KEY);
	        alertTypeSoundPreference.setOnPreferenceChangeListener(onPreferenceChangeListenerImpl());
	        
	        Preference alertTypeVibratePreference = getPreferenceScreen().findPreference(PreferenceLauncherActivity.TICKER_ALERTTYPE_VIBRATE_KEY);
	        alertTypeVibratePreference.setOnPreferenceChangeListener(onPreferenceChangeListenerImpl());
	        
	        
	    }

	private OnPreferenceChangeListener onPreferenceChangeListenerImpl() {
		return new OnPreferenceChangeListener(){
			public boolean onPreferenceChange(Preference preference, Object newValue) {
				preference.setSummary(SELECTED_TEXT + newValue);
				return true;
			}
			
		};
	}
	  
}
